/**
 * Copyright 2008 Matthew DeLambo
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.delambo.drool.interfaces;

public interface PoolNode<R extends Resource, T> {

    interface Factory <R> {
        PoolNode create(R r);
    } 

    /**
     * Gets the pooling resource from this node.
     * @return nodes resource.
     */
    public T getResource();

    /**
     * Validates the nodes resource.
     */
    public boolean resourceValidates();
    
    /**
     * Kills this nodes resource.
     */
    public void killResource();
    
    /**
     * Expires the lease for this node.
     */
    public void expireLease();
    
    /**
     * Gets the amount of time this node has been leased.
     * @return lease time.
     */
    public long getLeaseTime();
    
    /**
     * Gets the amount of time since the last use of this node.
     * @return time last used.
     */
    public long getLastUse();
    
    /**
     * Leases this node.
     */
    public void lease();
    
    /**
     * Returns the result for wether or not this node is leased.
     * @return true if node is leased; otherwise, false.
     */
    public boolean inUse();
    
    /**
     * Cleans the leasing status of this node, resetting it to unleased.
     */
    public void cleanUp();

    /**
     * Initializes this node, setting it to unleased.
     */
    public void init();
}
